using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using JSON;

public class JSONBoxShop{
	#region 单例
	private static JSONBoxShop instance;
	public static JSONBoxShop getInstance(){
	if (instance == null)
		instance = new JSONBoxShop ();
		return instance;
	}
	#endregion

	#region 变量
	private JSONNode json;
	private JSONNode JSONData{
		get{
			if(json == null)
				json = JsonRead.Read("JSONBoxShop");
			return json;
		}
	}
	#endregion
	#region 外部调用
	public void Clear(){
		json = null;
	}
	public JSONNode GetJSON(string key){
		return JSONData [key];
	}
	public JSONNode GetJSON(int index){
		return JSONData [index];
	}
	/// <summary>
	/// 有多少个数据
	/// </summary>
	public int GetCount(){
	return JSONData.Count;
	}

    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListID(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetID(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 商品id
	/// </summary>
	public int GetID(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["ID"].AsInt;
		return  value;
	}
	/// <summary>
	/// 商品id :From Index
	/// </summary>
	public int GetID(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetID(index.ToString());
			return  value;
		}
		value = json["ID"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListname(string target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( Getname(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 商品名称
	/// </summary>
	public string Getname(string key){
		JSONNode json = GetJSON (key);
		string  value;
		value = json["name"].ToString();
		return  value;
	}
	/// <summary>
	/// 商品名称 :From Index
	/// </summary>
	public string Getname(int index){
		string value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = Getname(index.ToString());
			return  value;
		}
		value = json["name"].ToString();
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListtype(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( Gettype(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 商店类型
	/// </summary>
	public int Gettype(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["type"].AsInt;
		return  value;
	}
	/// <summary>
	/// 商店类型 :From Index
	/// </summary>
	public int Gettype(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = Gettype(index.ToString());
			return  value;
		}
		value = json["type"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListcommodity(string target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( Getcommodity(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 商店内容
	/// </summary>
	public string Getcommodity(string key){
		JSONNode json = GetJSON (key);
		string  value;
		value = json["commodity"].ToString();
		return  value;
	}
	/// <summary>
	/// 商店内容 :From Index
	/// </summary>
	public string Getcommodity(int index){
		string value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = Getcommodity(index.ToString());
			return  value;
		}
		value = json["commodity"].ToString();
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListrank(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( Getrank(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 阶数
	/// </summary>
	public int Getrank(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["rank"].AsInt;
		return  value;
	}
	/// <summary>
	/// 阶数 :From Index
	/// </summary>
	public int Getrank(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = Getrank(index.ToString());
			return  value;
		}
		value = json["rank"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListprice(string target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( Getprice(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 商品售价
	/// </summary>
	public string Getprice(string key){
		JSONNode json = GetJSON (key);
		string  value;
		value = json["price"].ToString();
		return  value;
	}
	/// <summary>
	/// 商品售价 :From Index
	/// </summary>
	public string Getprice(int index){
		string value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = Getprice(index.ToString());
			return  value;
		}
		value = json["price"].ToString();
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListIcon(string target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetIcon(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 物品图标
	/// </summary>
	public string GetIcon(string key){
		JSONNode json = GetJSON (key);
		string  value;
		value = json["Icon"].ToString();
		return  value;
	}
	/// <summary>
	/// 物品图标 :From Index
	/// </summary>
	public string GetIcon(int index){
		string value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetIcon(index.ToString());
			return  value;
		}
		value = json["Icon"].ToString();
		return  value;
	}

	#endregion
}